package com.sskj.qiangjin.ui.fragment;

import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.sskj.common.util.ClickUtil;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseFragment;
import com.sskj.qiangjin.R;
import com.sskj.qiangjin.bean.ShowPayBean;
import com.sskj.qiangjin.presenter.AddPayWayPresenter;

import butterknife.BindView;

/**
 * Created by Q-Kang on 2019/1/20.
 */

@Route(path = RConfig.APP_FRAGMENT_PAY_WAY)
public class AddPayWayFragment extends BaseFragment<AddPayWayPresenter> {
    @BindView(R.id.et_alipay)
    EditText etAlipay;
    @BindView(R.id.et_real_name)
    EditText etRealName;
    @BindView(R.id.et_idcard)
    EditText etIdcard;
    @BindView(R.id.et_opening_bank)
    EditText etOpeningBank;
    @BindView(R.id.et_usdt_address)
    EditText et_usdt_address;
    @BindView(R.id.et_opening_branch_bank)
    EditText et_opening_branch_bank;
    @BindView(R.id.btn_save_pay_way)
    Button btnSavePayWay;

    @Override
    protected int getLayoutId() {
        return R.layout.app_fragment_pay_way;
    }

    @Override
    protected AddPayWayPresenter getPresenter() {
        return new AddPayWayPresenter();
    }

    @Override
    public void initView() {
        super.initView();
        mPresenter.showPay();
        ClickUtil.click(btnSavePayWay, () -> {
            if (TextUtils.isEmpty(etRealName.getText().toString().trim())) {
                ToastUtil.showShort("请输入您的真实姓名");
                return;
            }
            if (TextUtils.isEmpty(etIdcard.getText().toString().trim())) {
                ToastUtil.showShort("请输入您的银行卡号");
                return;
            }
            if (TextUtils.isEmpty(etOpeningBank.getText().toString().trim())) {
                ToastUtil.showShort("请输入您的银行卡开户行");
                return;
            }
            if (TextUtils.isEmpty(et_opening_branch_bank.getText().toString().trim())) {
                ToastUtil.showShort("请输入您的银行卡开户行支行");
                return;
            }
//            if (TextUtils.isEmpty(et_usdt_address.getText().toString().trim())) {
//                ToastUtil.showShort("请输入钱包地址");
//                return;
//            }
            mPresenter.addPayWay(et_usdt_address.getText().toString().trim()
                    , etRealName.getText().toString().trim()
                    , etIdcard.getText().toString().trim()
                    , etOpeningBank.getText().toString().trim()
                    , et_opening_branch_bank.getText().toString().trim());
        });
    }

    public void showPayWay(ShowPayBean showPayBean) {
        etRealName.setText(showPayBean.getRealname());
        etIdcard.setText(showPayBean.getBankcard());
        etOpeningBank.setText(showPayBean.getBranch());
        et_opening_branch_bank.setText(showPayBean.getBank());
        et_usdt_address.setText(showPayBean.getAddress());
    }

}
